﻿
@using LERP.Domain.Enums
@using LERP.Web.App_Start
@using Sharp.Framework
@using Sharp.Framework.Extensions

@model List<LERP.Web.Controllers.ViewModels.CustomerViewModels.CustomerViewModel>
@{
    ViewBag.Title = "客户列表";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
  
@Html.ActionLinkEx("新建父级客户", "CreateFirst", "Customer", new { returnUrl = Request.RawUrl }, new { style = "float: right;display: inline;" })
<br/>
<div id="treeDiv"  class="empty" style="text-align: left;">
        <ul class="jqueryFileTree">
    @foreach (var item in Model.Where(m => m.Level == CustomerLevel.First))
    {
        var list = Model.Where(x => x.ParentId == item.Id);
        <li class="directory collapsed">
            <span>  <a  class="treename">@item.Name   </a>
                
                @Html.ActionLinkEx("货品配置", "Goods", "Customer", new {id = item.Id, returnUrl = Request.RawUrl,name=item.Name}, new {@class = "action"}) 
                @if (!list.Any())
                {
                    @Html.ActionLinkEx("删除", "Delete", "Customer", new {id = item.Id, returnUrl = Request.RawUrl}, new {@class = "action delete"})
                }  
                @Html.ActionLinkEx("修改", "Edit", "Customer", new {id = item.Id, returnUrl = Request.RawUrl}, new {@class = "action"}) 
                @Html.ActionLinkEx("添加", "CreateSecond", "Customer", new {parentId = item.Id,  returnUrl = Request.RawUrl}, new {@class = "action",title="添加子级客户"})

            </span>
            <ul class="jqueryFileTree">
                @foreach (var second in list)
                {
                    var thirds = Model.Where(x => x.ParentId == second.Id);
                    <li class="directory collapsed">
                        <span>  <a  class="treename">@second.Name   </a>
                @Html.ActionLinkEx("货品配置", "Goods", "Customer", new {id = second.Id, returnUrl = Request.RawUrl,name=item.Name+second.Name}, new {@class = "action"}) 
                            @if (!thirds.Any())
                            {
                                @Html.ActionLinkEx("删除", "Delete", "Customer", new {id = second.Id, returnUrl = Request.RawUrl}, new {@class = "action delete"})
                            }  
                            @Html.ActionLinkEx("修改", "Edit", "Customer", new {id = second.Id, returnUrl = Request.RawUrl}, new {@class = "action"})
                            @Html.ActionLinkEx("添加", "CreateThird", "Customer", new {parentId = second.Id,  returnUrl = Request.RawUrl}, new {@class = "action",title="添加孙级客户"}) 

                        </span>
                        <ul class="jqueryFileTree">
                            @foreach (var node in thirds)
                            {

                                <li class="file ext_code">
                                    <span><a  class="treename">@node.Name</a>
                @Html.ActionLinkEx("货品配置", "Goods", "Customer", new {id = node.Id, returnUrl = Request.RawUrl,name=item.Name+second.Name+node.Name}, new {@class = "action"}) 
                                        @Html.ActionLinkEx("删除", "Delete", "Customer", new {id = node.Id, returnUrl = Request.RawUrl}, new {@class = "action delete"}) 
                                        @Html.ActionLinkEx("修改", "Edit", "Customer", new {id = node.Id, returnUrl = Request.RawUrl}, new {@class = "action",}) 
                                    </span>
                                </li>
                            }
    
                        </ul>
                    </li>
                }
    
            </ul>
        </li>

    }
</ul>
</div>
       @section Scripts {
    <script type="text/javascript">

        $(function () {
            $("a.delete").click(function () {
                return window.confirm("您确认要"+$(this).html()+"当前客户么?");
            });
           
        })

    </script>

}
